package net.gyapp.markim.core;


import android.content.Context;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Vibrator;
import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.easyder.wrapper.core.scheduler.TaskScheduler;
import com.easyder.wrapper.utils.LogUtils;
import com.xuhao.android.libsocket.packet.ImConfig;
import com.xuhao.android.libsocket.packet.PulseSendableIml;
import com.xuhao.android.libsocket.sdk.ConnectionInfo;
import com.xuhao.android.libsocket.sdk.ISendableIml;
import com.xuhao.android.libsocket.sdk.OkSocket;
import com.xuhao.android.libsocket.sdk.OkSocketOptions;
import com.xuhao.android.libsocket.sdk.SocketActionAdapter;
import com.xuhao.android.libsocket.sdk.bean.IPulseSendable;
import com.xuhao.android.libsocket.sdk.bean.ISendable;
import com.xuhao.android.libsocket.sdk.connection.IConnectionManager;
import com.xuhao.android.libsocket.sdk.connection.interfacies.ISocketActionListener;
import com.xuhao.android.libsocket.utils.ActivityStack;
import com.xuhao.android.libsocket.utils.Logger;

import net.gyapp.markim.WrapperApplication;
import net.gyapp.markim.core.entity.ConversationEntity;
import net.gyapp.markim.core.entity.MessageEntity;
import net.gyapp.markim.core.reponse.ChatResponse;
import net.gyapp.markim.core.reponse.ImResponse;
import net.gyapp.markim.module.basic.Helper;
import net.gyapp.markim.module.message.bean.VoiceBean;

import org.jim.common.base.ImPacket;
import org.jim.common.packets.ChatBody;
import org.jim.common.packets.ChatType;
import org.jim.common.packets.CloseReqBody;
import org.jim.common.packets.Command;
import org.jim.common.packets.LoginReqBody;
import org.jim.common.packets.MessageReqBody;
import org.jim.common.packets.MsgType;
import org.jim.common.packets.UserReqBody;
import org.jim.common.tcp.TcpPacket;

/**
 * Auther:  winds
 * Email:   heardown@163.com
 * Date:    2018/7/16.
 * Desc:
 */

public class ImManager {
    IConnectionManager manager;
    Ringtone mRingtone;
    SocketActionAdapter listener;

    private ImManager() {
        OkSocket.initialize(WrapperApplication.getInstance(), true);
        initListener();
        initChannel();
        initRingtone();
        initVibrate();
    }

    private static class ConfigBuilder {
        private static ImManager helper = new ImManager();
    }

    /**
     * 获取实例化的方法  第一次实例化 请在application   同时调用init方法
     *
     * @return
     */
    public static ImManager getInstance() {
        return ImManager.ConfigBuilder.helper;
    }

    /**
     * 获取管理对象
     *
     * @return
     */
    public IConnectionManager getConnectionManager() {
        return manager;
    }

    /**
     * 初始化连接
     *
     * @param listener
     */
    public void initChannel(ISocketActionListener listener) {
        if (manager == null) {
            ConnectionInfo info = new ConnectionInfo(ImConfig.IP, ImConfig.PORT);
            OkSocketOptions mOkOptions = new OkSocketOptions.Builder()
                    .setPulseFrequency(ImConfig.HEART_FREQUENCY)
                    .setMaxReadDataMB(ImConfig.MAX_READ_SIZE_MB)
                    .build();
            manager = OkSocket.open(info).option(mOkOptions);
        }
        if (manager != null) {
            manager.registerReceiver(listener);
            if (!manager.isConnect()) {
                manager.connect();
            }
        }
    }

    private void initRingtone() {
        if (mRingtone == null) {
            Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            mRingtone = RingtoneManager.getRingtone(WrapperApplication.getInstance(), uri);
        }
    }

    Vibrator mVibrator;

    private void initVibrate() {
        if (mVibrator == null) {
            mVibrator = (Vibrator) WrapperApplication.getInstance().getSystemService(Context.VIBRATOR_SERVICE);
        }
    }

    public void playVibrate() {
        if (mVibrator == null) {
            initVibrate();
        }
        if (mVibrator != null) {
            if (!ActivityStack.isBackground()) { //当前存在任务栈
                mVibrator.vibrate(200);
            }
        }
    }

    public void playRingtone() {
        if (mRingtone == null) {
            initRingtone();
        }
        if (mRingtone != null) {
            if (!mRingtone.isPlaying()) {
                if (!ActivityStack.isBackground()) { //当前存在任务栈
                    mRingtone.play();
                }
            }
        }
    }

    private void initListener() {
        if (listener == null) {
            listener = new SocketActionAdapter() {
                @Override
                public void onSocketConnectionSuccess(Context context, ConnectionInfo info, String action) {
                    super.onSocketConnectionSuccess(context, info, action);
                    LogUtils.i(" -- Socket -- ", "onSocketConnectionSuccess");
                    startHeartbeat(info, new PulseSendableIml());
                    if (ActivityStack.isBackground() || ActivityStack.size() <= 0) { //在通过推送保活的情况下  偷偷自动登陆
                        LogUtils.i(" -- Socket -- ", "Auto login background");
                        retryAutoLogin();
                    }
                }

                @Override
                public void onSocketReadResponse(Context context, ConnectionInfo info, String action, ImPacket packet) {
                    if (packet.getCommand() == Command.COMMAND_HEARTBEAT_REQ) {
                        manager
                                .getPulseManager()
                                .feed();
                    } else {
                        onMessageReceive(context, info, action, PacketHelper.parsePacket(packet));
                    }
                }

                @Override
                public void onSocketWriteResponse(Context context, ConnectionInfo info, String action, ISendable data) {
                    super.onSocketWriteResponse(context, info, action, data);
                    LogUtils.i(" -- Socket -- ", "onSocketWriteResponse 发送数据成功");
                }

            };
        }
    }

    private void initChannel() {
        if (listener == null) {
            initListener();
        }
        initChannel(listener);
    }

    private void onMessageReceive(Context context, final ConnectionInfo info, String action, final ImResponse response) {
        if (response != null) {
            TaskScheduler.execute(new Runnable() {
                @Override
                public void run() {
                    ImProcessor.processResponseData(info, response);
                }
            });
        }

    }


    /**
     * 回调注册
     *
     * @param listener
     * @return
     */
    public ISocketActionListener registerReceiver(ISocketActionListener listener) {
        initChannel(listener);
        return listener;
    }

    /**
     * 取消回调注册
     *
     * @param listener
     */
    public void unRegisterReceiver(ISocketActionListener listener) {
        if (manager != null) {
            manager.unRegisterReceiver(listener);
        }
    }

    /**
     * 判断是否连接
     *
     * @return
     */
    public boolean isConnect() {
        return manager != null && manager.isConnect();
    }

    /**
     * 连接
     */
    public void connect() {
        if (manager != null && !manager.isConnect()) {
            manager.connect();
        }
    }

    /**
     * 主动断开连接
     */
    public void disconnect() {
        if (manager != null) {
            manager.disconnect();
        }
    }

    /**
     * 發送心跳
     *
     * @param info
     * @param sendable
     */
    private void startHeartbeat(ConnectionInfo info, IPulseSendable sendable) {
        OkSocket.open(info)
                .getPulseManager()
                .setPulseSendable(sendable)
                .pulse();
    }

    /**
     * 检查连接状况
     *
     * @return
     */
    private boolean checkStatus() {
        if (manager == null) {
            initChannel();
        }
        if (manager != null) {
            if (!manager.isConnect()) {
                manager.connect();
            }
            if (manager.isConnect()) {
                return true;
            }
        }
        return false;
    }

    /**
     * 发送消息
     *
     * @param packet
     * @return
     */
    public boolean send(ImPacket packet) {
        boolean status = checkStatus();
        if (status) {
            manager.send(new ISendableIml(packet));
        }
        return status;
    }

    /**
     * 登陆
     *
     * @param account
     * @param cipher
     * @return
     */
    public boolean login(String account, String cipher) {
        return send(new TcpPacket(Command.COMMAND_LOGIN_REQ, new LoginReqBody(account, cipher).toByte()));
    }

    public boolean retryAutoLogin() {
        String account = Helper.getAccount();
        String cipher = Helper.getCipher();
        if (!TextUtils.isEmpty(account) && !TextUtils.isEmpty(cipher)) {
            if (!ImManager.getInstance().isConnect()) {
                ImManager.getInstance().connect();
            }
            ImManager.getInstance().login(account, cipher);
            return true;
        }
        return false;
    }

    public void logout(String userId) {
        if (checkStatus()) {
            send(new TcpPacket(Command.COMMAND_CLOSE_REQ, new CloseReqBody(userId).toByte()));
            if (manager.isConnect()) {
                manager.disconnect();
            }
        }
    }

    /**
     * 登陆
     *
     * @param token
     * @return
     */
    public boolean login(String token) {
        return send(new TcpPacket(Command.COMMAND_LOGIN_REQ, new LoginReqBody(token).toByte()));
    }


    /**
     * 获取所有离线消息
     *
     * @return
     */
    public boolean getOfflineMessage() {
        MessageReqBody body = new MessageReqBody();
        body.setType(0);
        body.setUserId(ImHelper.getSelf());
        return send(new TcpPacket(Command.COMMAND_GET_MESSAGE_REQ, body.toByte()));
    }

    public boolean getUser(String userId) {
        UserReqBody body = new UserReqBody();
        body.setType(0);
        body.setUserid(userId);
        return send(new TcpPacket(Command.COMMAND_GET_USER_REQ, body.toByte()));
    }

    public boolean getAllUser() {
        UserReqBody body = new UserReqBody();
        body.setType(2);
        body.setUserid(ImHelper.getSelf());
        return send(new TcpPacket(Command.COMMAND_GET_USER_REQ, body.toByte()));
    }

    public MessageEntity sendMessage(ConversationEntity conversation, MessageEntity entity) {
        boolean status = checkStatus();
        ChatBody body = new ChatBody();
        body.setFrom(entity.from); //来源ID
        if (entity.chatType == ChatType.CHAT_TYPE_PRIVATE.getNumber()) { //目标ID
            body.setTo(entity.to);
        }
        body.setCreateTime(entity.createTime); //创建时间
        body.setMsgType(entity.msgType); //消息类型    (0:text、1:image、2:voice、3:vedio、4:music、5:news)"

        body.setChatType(entity.chatType);//聊天类型int类型(0:未知,1:公聊,2:私聊)"

        if (entity.chatType == ChatType.CHAT_TYPE_PUBLIC.getNumber()) {
            body.setGroup_id(entity.group_id);//群组id仅在chatType为(1)时需要,String类型"
        }
        body.setContent(entity.content); //内容
        TcpPacket packet = new TcpPacket(Command.COMMAND_CHAT_REQ, body.toByte());
        Logger.i(body.toString());
        send(packet);
        return generateMessageEntity(conversation, entity, status);
    }

    public boolean recallMessage(MessageEntity entity) {
        boolean status = checkStatus();
        ChatBody body = new ChatBody();
        body.setFrom(entity.from); //来源ID
        if (entity.chatType == ChatType.CHAT_TYPE_PRIVATE.getNumber()) { //目标ID
            body.setTo(entity.to);
        }
        body.setCreateTime(entity.createTime); //创建时间
        body.setMsgType(entity.msgType); //消息类型    (0:text、1:image、2:voice、3:vedio、4:music、5:news)"

        body.setChatType(entity.chatType);//聊天类型int类型(0:未知,1:公聊,2:私聊)"

        if (entity.chatType == ChatType.CHAT_TYPE_PUBLIC.getNumber()) {
            body.setGroup_id(entity.group_id);//群组id仅在chatType为(1)时需要,String类型"
        }
        body.setId(entity.messageId);
        body.setContent(entity.messageId); //内容
        body.setCreateTime(entity.createTime); //时间
        body.setCmd(Command.COMMAND_CANCEL_MSG_REQ.getNumber()); //命令
        return send(new TcpPacket(Command.COMMAND_CANCEL_MSG_REQ, body.toByte()));
    }


    /**
     * 生成消息实体  在私聊时主动添加到数据 且更新会话信息
     *
     * @param conversation
     * @param status
     * @return
     */
    private MessageEntity generateMessageEntity(ConversationEntity conversation, MessageEntity entity, boolean status) {
        entity.isSending = 0;  //完成准备发送的状态
        entity.isFailed = status ? 0 : 1;

        //更新会话信息
        conversation.latestTime = entity.createTime;
        conversation.latestMsg = entity.content;
        conversation.latestMsgType = entity.msgType;
        conversation.latestNick = entity.fromNick;
        conversation.latestAvatar = entity.fromAvatar;


        //需要存储到数据库
        ImHelper.insertMessage(entity);
        ImProcessor.updateOrInsertConversation(conversation);

        return entity;
    }

    public IResult sendMessage(String from, String to, long time, MsgType msgType, ChatType chatType, String groupId, String content) {
        boolean status = checkStatus();
        ChatBody body = new ChatBody();
        body.setFrom(from); //来源ID
        if (chatType == ChatType.CHAT_TYPE_PUBLIC) { //目标ID
            body.setTo(to);
        }
        body.setCreateTime(time); //创建时间
        body.setMsgType(msgType.getNumber()); //消息类型    (0:text、1:image、2:voice、3:vedio、4:music、5:news)"

        body.setChatType(chatType.getNumber());//聊天类型int类型(0:未知,1:公聊,2:私聊)"

        if (chatType == ChatType.CHAT_TYPE_PUBLIC) {
            body.setGroup_id(groupId);//群组id仅在chatType为(1)时需要,String类型"
        }
        body.setContent(content); //内容
        TcpPacket packet = new TcpPacket(Command.COMMAND_CHAT_REQ, body.toByte());
        Logger.i(packet.toString());
        send(packet);

        return generateResult(status, from, to, time, msgType, chatType, groupId, content);
    }

    /**
     * 分发消息
     *
     * @param from
     * @param to
     * @param time
     * @param msgType
     * @param chatType
     * @param groupId
     * @param content
     * @return
     */
    public boolean dispatchMessage(String from, String to, long time, MsgType msgType, ChatType chatType, String groupId, String content) {
        ChatBody body = new ChatBody();
        body.setFrom(from); //来源ID
        if (chatType == ChatType.CHAT_TYPE_PRIVATE) { //目标ID
            body.setTo(to);
        }
        body.setCreateTime(time); //创建时间
        body.setMsgType(msgType.getNumber()); //消息类型    (0:text、1:image、2:voice、3:vedio、4:music、5:news)"

        body.setChatType(chatType.getNumber());//聊天类型int类型(0:未知,1:公聊,2:私聊)"

        if (chatType == ChatType.CHAT_TYPE_PUBLIC) {
            body.setGroup_id(groupId);//群组id仅在chatType为(1)时需要,String类型"
        }
        body.setContent(content); //内容
        LogUtils.info("--> " + body.toString());
        TcpPacket packet = new TcpPacket(Command.COMMAND_CHAT_REQ, body.toByte());

        return send(packet);
    }

    private IResult generateResult(boolean status, String from, String to, long time, MsgType msgType, ChatType chatType, String groupId, String content) {
        ChatResponse response = new ChatResponse();
        response.command = Command.COMMAND_CHAT_REQ.getNumber();
        response.data = new ChatResponse.DataBean();
        response.data.from = from;
        response.data.to = to;
        response.data.msgType = msgType.getNumber();
        response.data.chatType = chatType.getNumber();
        response.data.group_id = groupId;
        response.data.content = content;
        response.isDirect = true;
        return new IResult(status, response);
    }

    /**
     * 发送文本消息
     *
     * @param conversation
     * @param content
     * @return
     */
    public MessageEntity sendTextMessage(ConversationEntity conversation, String content) {
        long timestamp = ImHelper.getTimestamp();
        boolean status = dispatchMessage(ImHelper.getSelf(), conversation.sessionIdStr, timestamp, MsgType.MSG_TYPE_TEXT,
                ChatType.valueOf(conversation.chatType), conversation.sessionIdStr, content);

        return generateMessageEntity(conversation, content, MsgType.MSG_TYPE_TEXT, timestamp, status);
    }

    /**
     * 发送文本消息
     *
     * @param conversation
     * @param content
     * @return
     */
    public MessageEntity sendImageMessage(ConversationEntity conversation, String content) {
        long timestamp = ImHelper.getTimestamp();
        boolean status = dispatchMessage(ImHelper.getSelf(), conversation.sessionIdStr, timestamp, MsgType.MSG_TYPE_IMG,
                ChatType.valueOf(conversation.chatType), conversation.sessionIdStr, content);

        return generateMessageEntity(conversation, content, MsgType.MSG_TYPE_IMG, timestamp, status);
    }

    /**
     * 生成消息实体  在私聊时主动添加到数据 且更新会话信息
     *
     * @param conversation
     * @param content
     * @param msgType
     * @param timestamp
     * @param isFailed
     * @return
     */
    private MessageEntity generateMessageEntity(ConversationEntity conversation, String content, MsgType msgType, long timestamp, boolean isFailed) {
        MessageEntity entity = new MessageEntity();
        entity.conversationId = conversation.id;
        entity.userId = conversation.userId;
        entity.chatType = conversation.chatType;
        entity.msgType = msgType.getNumber();
        entity.content = content;
        entity.cmd = Command.COMMAND_CHAT_REQ.getNumber();
        entity.createTime = timestamp;

        entity.from = ImHelper.getSelf();
        entity.fromNick = ImHelper.getSelfNick();
        entity.fromAvatar = ImHelper.getSelfAvatar();

        if (entity.chatType == ChatType.CHAT_TYPE_PUBLIC.getNumber()) {
            entity.group_id = conversation.sessionIdStr;
        } else {
            entity.to = conversation.sessionIdStr;
            entity.toNick = conversation.name;
            entity.toAvatar = conversation.avatar;
        }
        entity.isRead = 1;
        entity.isOwnSend = 1;
        entity.isFailed = isFailed ? 1 : 0;

        //更新会话信息
        conversation.latestTime = entity.createTime;
        conversation.latestMsg = entity.content;
        conversation.latestMsgType = entity.msgType;
        conversation.latestNick = entity.fromNick;
        conversation.latestAvatar = entity.fromAvatar;

        if (entity.chatType == ChatType.CHAT_TYPE_PRIVATE.getNumber()) {
            //需要存储到数据库
            ImHelper.insertMessage(entity);
            ImProcessor.updateOrInsertConversation(conversation);
        }
        return entity;
    }

    /**
     * 预生成消息实体  暂添加到数据库
     *
     * @param conversation
     * @param timestamp
     * @return
     */
    public MessageEntity preGenerateTextMessageEntity(ConversationEntity conversation, String content, long timestamp) {
        MessageEntity entity = new MessageEntity();
        entity.conversationId = conversation.id;
        entity.userId = conversation.userId;
        entity.chatType = conversation.chatType;
        entity.msgType = MsgType.MSG_TYPE_TEXT.getNumber();
        entity.content = content;
        entity.cmd = Command.COMMAND_CHAT_REQ.getNumber();
        entity.createTime = timestamp;

        entity.from = ImHelper.getSelf();
        entity.fromNick = ImHelper.getSelfNick();
        entity.fromAvatar = ImHelper.getSelfAvatar();


        if (entity.chatType == ChatType.CHAT_TYPE_PUBLIC.getNumber()) {
            entity.group_id = conversation.sessionIdStr;
        } else {
            entity.to = conversation.sessionIdStr;
            entity.toNick = conversation.name;
            entity.toAvatar = conversation.avatar;
        }
        entity.isRead = 1;
        entity.isOwnSend = 1;
        entity.isSending = 1;

        return entity;
    }

    /**
     * 预生成消息实体  暂添加到数据库
     *
     * @param conversation
     * @param timestamp
     * @return
     */
    public MessageEntity preGenerateImageMessageEntity(ConversationEntity conversation, String content, long timestamp) {
        MessageEntity entity = new MessageEntity();
        entity.conversationId = conversation.id;
        entity.userId = conversation.userId;
        entity.chatType = conversation.chatType;
        entity.msgType = MsgType.MSG_TYPE_IMG.getNumber();
        entity.content = content;
        entity.cmd = Command.COMMAND_CHAT_REQ.getNumber();
        entity.createTime = timestamp;

        entity.from = ImHelper.getSelf();
        entity.fromNick = ImHelper.getSelfNick();
        entity.fromAvatar = ImHelper.getSelfAvatar();


        if (entity.chatType == ChatType.CHAT_TYPE_PUBLIC.getNumber()) {
            entity.group_id = conversation.sessionIdStr;
        } else {
            entity.to = conversation.sessionIdStr;
            entity.toNick = conversation.name;
            entity.toAvatar = conversation.avatar;
        }
        entity.isRead = 1;
        entity.isOwnSend = 1;
        entity.isSending = 1;


        return entity;
    }

    /**
     * 预生成消息实体  暂添加到数据库
     *
     * @param conversation
     * @param timestamp
     * @return
     */
    public MessageEntity preGenerateVoiceMessageEntity(ConversationEntity conversation, String path, double length, long timestamp) {
        MessageEntity entity = new MessageEntity();
        entity.conversationId = conversation.id;
        entity.userId = conversation.userId;
        entity.chatType = conversation.chatType;
        entity.msgType = MsgType.MSG_TYPE_VOICE.getNumber();
        entity.content = generateVoiceMessageContent(path, length);
        entity.cmd = Command.COMMAND_CHAT_REQ.getNumber();
        entity.createTime = timestamp;

        entity.from = ImHelper.getSelf();
        entity.fromNick = ImHelper.getSelfNick();
        entity.fromAvatar = ImHelper.getSelfAvatar();

        entity.voiceLocalPath = path;

        if (entity.chatType == ChatType.CHAT_TYPE_PUBLIC.getNumber()) {
            entity.group_id = conversation.sessionIdStr;
        } else {
            entity.to = conversation.sessionIdStr;
            entity.toNick = conversation.name;
            entity.toAvatar = conversation.avatar;
        }
        entity.isRead = 1;
        entity.isOwnSend = 1;
        entity.isVoiceRead = 1;
        entity.isSending = 1;


        return entity;
    }

    public String generateVoiceMessageContent(String path, double length) {
        VoiceBean bean = new VoiceBean();
        bean.voicePath = path;
        bean.voiceRecordingSeconds = length;
        return JSON.toJSONString(bean);
    }

    /**
     * 发送群组文字消息
     *
     * @param from
     * @param time
     * @param groupId
     * @param content
     * @return
     */
    public IResult sendLetterGroupMessage(String from, long time, String groupId, String content) {
        return sendMessage(from, "", time, MsgType.MSG_TYPE_TEXT, ChatType.CHAT_TYPE_PUBLIC, groupId, content);
    }

    /**
     * 发送文字消息
     *
     * @param from
     * @param time
     * @param content
     * @return
     */
    public IResult sendLetterMessage(String from, String to, long time, String content) {
        return sendMessage(from, to, time, MsgType.MSG_TYPE_TEXT, ChatType.CHAT_TYPE_PRIVATE, "", content);
    }

    /**
     * 发送群图片消息
     *
     * @param from
     * @param time
     * @param groupId
     * @param content
     * @return
     */
    public IResult sendImageGroupMessage(String from, long time, String groupId, String content) {
        return sendMessage(from, "", time, MsgType.MSG_TYPE_IMG, ChatType.CHAT_TYPE_PUBLIC, groupId, content);
    }

    /**
     * 发送图片消息
     *
     * @param from
     * @param to
     * @param time
     * @param content
     * @return
     */
    public IResult sendImageMessage(String from, String to, long time, String content) {
        return sendMessage(from, to, time, MsgType.MSG_TYPE_IMG, ChatType.CHAT_TYPE_PRIVATE, "", content);
    }

    /**
     * 发送群音频消息
     *
     * @param from
     * @param time
     * @param groupId
     * @param content
     * @return
     */
    public IResult sendVoiceGroupMessage(String from, long time, String groupId, String content) {
        return sendMessage(from, "", time, MsgType.MSG_TYPE_VOICE, ChatType.CHAT_TYPE_PUBLIC, groupId, content);
    }

    /**
     * 发送音频消息
     *
     * @param from
     * @param to
     * @param time
     * @param content
     * @return
     */
    public IResult sendVoiceImageMessage(String from, String to, long time, String content) {
        return sendMessage(from, to, time, MsgType.MSG_TYPE_VOICE, ChatType.CHAT_TYPE_PRIVATE, "", content);
    }

    /**
     * 发送群视频消息
     *
     * @param from
     * @param time
     * @param groupId
     * @param content
     * @return
     */
    public IResult sendVideoGroupMessage(String from, long time, String groupId, String content) {
        return sendMessage(from, "", time, MsgType.MSG_TYPE_VIDEO, ChatType.CHAT_TYPE_PUBLIC, groupId, content);
    }

    /**
     * 发送视频消息
     *
     * @param from
     * @param to
     * @param time
     * @param content
     * @return
     */
    public IResult sendVideoImageMessage(String from, String to, long time, String content) {
        return sendMessage(from, to, time, MsgType.MSG_TYPE_VIDEO, ChatType.CHAT_TYPE_PRIVATE, "", content);
    }

}
